package com.shanxi.cz.module.biz.dal.mysql.ammeterrecordday;

import java.util.*;

import cn.idev.excel.util.StringUtils;
import com.shanxi.cz.framework.common.pojo.PageResult;
import com.shanxi.cz.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.shanxi.cz.framework.mybatis.core.mapper.BaseMapperX;
import com.shanxi.cz.module.biz.dal.dataobject.ammeterrecord.AmmeterRecordDO;
import com.shanxi.cz.module.biz.dal.dataobject.ammeterrecordday.AmmeterRecordDayDO;
import org.apache.ibatis.annotations.Mapper;
import com.shanxi.cz.module.biz.controller.admin.ammeterrecordday.vo.*;

/**
 * 电表数据日报 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface AmmeterRecordDayMapper extends BaseMapperX<AmmeterRecordDayDO> {

    default PageResult<AmmeterRecordDayDO> selectPage(AmmeterRecordDayPageReqVO reqVO) {
        LambdaQueryWrapperX<AmmeterRecordDayDO> wrapperX = new LambdaQueryWrapperX<AmmeterRecordDayDO>()
                .eqIfPresent(AmmeterRecordDayDO::getAmmeterId, reqVO.getAmmeterId())
//                .betweenIfPresent(AmmeterRecordDayDO::getRecordDate, reqVO.getRecordDate())
                .eqIfPresent(AmmeterRecordDayDO::getHz, reqVO.getHz())
                .eqIfPresent(AmmeterRecordDayDO::getVoltageA, reqVO.getVoltageA())
                .eqIfPresent(AmmeterRecordDayDO::getVoltageB, reqVO.getVoltageB())
                .eqIfPresent(AmmeterRecordDayDO::getVoltageC, reqVO.getVoltageC())
                .eqIfPresent(AmmeterRecordDayDO::getVoltageAverage, reqVO.getVoltageAverage())
                .eqIfPresent(AmmeterRecordDayDO::getElectricityA, reqVO.getElectricityA())
                .eqIfPresent(AmmeterRecordDayDO::getElectricityB, reqVO.getElectricityB())
                .eqIfPresent(AmmeterRecordDayDO::getElectricityC, reqVO.getElectricityC())
                .eqIfPresent(AmmeterRecordDayDO::getElectricityAverage, reqVO.getElectricityAverage())
                .eqIfPresent(AmmeterRecordDayDO::getPower, reqVO.getPower())
                .eqIfPresent(AmmeterRecordDayDO::getPowerMax, reqVO.getPowerMax())
                .eqIfPresent(AmmeterRecordDayDO::getPowerFactor, reqVO.getPowerFactor())
                .eqIfPresent(AmmeterRecordDayDO::getEng, reqVO.getEng())
                .eqIfPresent(AmmeterRecordDayDO::getReduction, reqVO.getReduction())
                .betweenIfPresent(AmmeterRecordDayDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(AmmeterRecordDayDO::getId);
        if(StringUtils.isNotBlank(reqVO.getRecordDateFrom()) && StringUtils.isNotBlank(reqVO.getRecordDateTo())){
            wrapperX.betweenIfPresent(AmmeterRecordDayDO::getRecordDate, new String[]{reqVO.getRecordDateFrom(), reqVO.getRecordDateTo()});
        }
        return selectPage(reqVO, wrapperX);
    }

    default List<AmmeterRecordDayDO> selectList(AmmeterRecordDayPageReqVO pageReqVO){
        return selectList(new LambdaQueryWrapperX<AmmeterRecordDayDO>()
                .eqIfPresent(AmmeterRecordDayDO::getAmmeterId, pageReqVO.getAmmeterId())
                .likeIfPresent(AmmeterRecordDayDO::getRecordDate, pageReqVO.getRecordDate())
                .orderByDesc(AmmeterRecordDayDO::getCreateTime));
    }
}